package partikelTest1;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
import java.awt.Color;

import javax.swing.JPanel;

public class ParticleViewer extends JPanel{
	
	List<Particle> partiklar = new ArrayList<Particle>();
	
	public ParticleViewer(){
		
		for(int i = 0; i<4; i++){
			partiklar.add(new Particle((int)(Math.random()*350), (int)(Math.random()*350)));
		}
		
	}
	
	public void paint(Graphics g){
		super.paint(g);
		
		for(Particle particle : partiklar){
			particle.update();
			particle.ritaUt(g);
		}
		for(Particle Theparticle : partiklar){
			for(Particle particle : partiklar){
				if((Math.abs(Theparticle.getXPos()-particle.getXPos())) <= 20 && Math.abs((Theparticle.getYPos()-particle.getYPos())) <= 20 && !particle.equals(Theparticle)){
					System.out.println("Krock"+particle.getXPos()+Theparticle.getXPos()+"-"+(particle.getYPos()-Theparticle.getYPos()));
					particle.collision();
				}
			}
		}
		
		
	}
	
	public List<Particle> getParticles(){
		return partiklar;
	}

}
